Pass matrix by const reference

In general, should be faster than passing it by value.
Use std::stack::emplace instead of push

For many calls (drawing many boxes), this significantly improves the
performance for me (optimized build, something like 4.0 s to 3.6 s for a
simple test).