Maximum matching on a tree
You can do much better. Consider for example the tree in which the root has $N$ children, and each one has one child. The maximum matching has size $N$, but the longest path is only four edges long.

Here is a better algorithm. Choose a root arbitrarily. For each subtree, calculate the maximum matching within the subtree, as well the maximum matching within the subtree that doesn't touch the root of the subtree. You can think of it as a form of dynamic programming.

Many problems on trees can be solved efficiently using this kind of dynamic programming.