Sure!
This code snippet would work for a batch size of 2.
Note that I assume you are using a constant number of selected features in each batch (in this case 3 features).
class MyModel(nn.Module):
    def __init__(self):
        super(MyModel, self).__init__()
        self.conv1 = nn.Conv2d(1, 5, 3, 1, 1)
        self.fc = nn.Linear(3*10*10, 10)
        
    def forward(self, x, index):
        x = self.conv1(x)
        x = x[index].view(x.size(0), -1)
        x = self.fc(x)
        return x

batch_size, c, h, w = 2, 1, 10, 10
x = torch.randn(batch_size, c, h, w)
index = torch.tensor([[0, 1, 0, 1, 1],
                      [1, 0, 1, 1, 0]], dtype=torch.bool)
    
model = MyModel()
out = model(x, index)