Write to a CV::Mat from a higher scope within a function
Assuming the matrix is always empty when passed into the function, the more normal way to write this would be to avoid any side effects and make cv_matrix the return type. i.e

cv::Mat read_matrix_from_param(ros::NodeHandle nodehandle, const std::string&amp; param)
{
    cv::Mat cv_matrix

    ...
    return cv_matrix;
}


As a side point you should pass in param and possibly nodehandle, as const &amp; to avoid unnecessary copies.

If this is not the case and you may pass in non-empty matrices ( I think that wouldn't make sense here ), then I would say using a non-const ref is fine. Alternative you could use a pointer i.e.

void read_matrix_from_param(ros::NodeHandle nodehandle, std::string param, cv::Mat *cv_matrix)
{
    ...

    cv::Mat(_rows, _cols, CV_64F, _data.data()).copyTo(*cv_matrix);
}


called as

read_matrix_from_param(private_nh, std::string("camera_matrix"), &amp;test_matrix1);

Personally I wouldn't use a pointer and Core C++ Guidelines recommends a reference, but looks like it is the style recommended by google see https://softwareengineering.stackexchange.com/questions/299021/non-optional-pointers-vs-non-const-references-in-c . If you are using clang-tidy google style guidelines are an option in that I believe so that may be where this warning is coming from.