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