dynamic-time-warping: Extract function to calculate accumulated cost matrix.