matrices should be passed by const reference