Write a Python program that would implement the Chamfer matching algorithm. Please note:
1. Write your own implementation of the algorithm. Do not use any ready functions of Chamfer matching.
2. Write also your own implementation of the distance transform function.
3. You can use the available edge detection functions in OpenCV.
Use your implementation for hand tracking in the provided video using the provided hand template. You should get results similar to the provided video illustration of the detection. Note the robustness of the algorithm when the size and orientation of the hand are similar to that of the template. Also, note the shortcomings of the algorithm when size and orientation change.