Efficient Algorithm for Calculating Similarity between Trajectories Containing an Increasing Dimension