Fix dependency resolution.

The "if (parent == root) return pidx;" line needed to be inside the "if(!matches" block.