Calculate average distance