I think the best approach would be to write a custom sampler by passing the targets to it and apply your sampling logic to return the right indices.
You could use one of the already implemented samplers from here 6 as the base class and add your filtering to it.