Hi,
//below code 
        objectness = objectness[batch_idx, top_n_idx]

I think, translate above line to cpp is
auto new_val0 = objectness.index_select(0, batch_idx);
auto new_val1 = objectness.index_select(1, top_n_idx);
objectness.index_copy_(0, batch_idx, new_val0);
objectness.index_copy_(1, top_n_idx, new_val1);