added threshold to nearest point search