BUG: linalg/flapack: fix invalid lwork checks in gerqf, orgrq and ungrq

This causes segfaults in test_lapack.py:test_ticket_1645