Function to check the distance between two points