Matrix approach to matching polynomials