If you want the output shape [2, 3, 5, 5], so you want to drop the indices of dim=1, your ids can only be of length 2 and with a max value of 3.
I got this running, but i dont think its the best way xD
ten = torch.randn(2, 4, 5, 5)
ids = torch.tensor([3, 1])
mask = torch.ones_like(ten).scatter_(1, ids[:, None, None, None].repeat(1, 1, 5, 5), 0.)
res = ten[mask.bool()].view(2, 3, 5, 5)