You could write a custom Dataset and return the index together with the data and target and store the index e.g. in a list.
Afterwards you could use these indices to map your samples using your condition.