calculate distance matrix function
better time selection