optimize queries using the distance function

using the concrete DistanceFilter implementation should
result in better performance than the generic function
filter.