The minimum salary required to work legally in Thailand (if I remember correctly) is 40.000 Baht. Just with that you can see that anyone making 20K doesn't have a working permit and matching visa. On top of that there's a bunch of requirements for foreigners and companies hiring foreigners (like having 3 or 4 Thais workers for every foreigner) so you'll see that most dive masters and instructors are not working "legally" (in quotes because the Law is a funny thing around here)
What AleG says is the "letter of the law" but doesn't really paint the true picture of what working legally as a dive instructor here entails. It's not super easy to jump through all of the bureaucratic hoops, but it's also not impossibly difficult.
In order to work legally as a freelance dive instructor, you first have to set up a Thai company with a majority of Thai directors/shareholders. A specialized paralegal will be able to take care of all of the details for you, including finding Thai company directors willing to be a part of your company. You or your wife may act as the managing director of this company. The company then issues a document that will allow you to go to a Thai consulate outside of Thailand to apply for a B visa (B = Business). You can take care of all of this paperwork before you even set foot in Thailand.
Once you are here, your company applies for a work permit for you as a foreign worker. There is a minimum registered capital value for a company with just one foreign employee, and a higher capital value for a company that wants to hire a second foreign employee. For each work permit your company obtains, you must also have some number of Thai employees--at least in theory. You don't actually have to have these employees at all, but there are some tax burdens imposed on the company regardless of whether or not these employees exist in reality. Countless companies exist with a foreign employee and fewer than four Thai employees.
Foreign employees pay taxes according to the minimum monthly salary stipulated (which depends on nationality). You don't actually have to EARN that amount of money, but you do have to PAY TAX on that level of earnings even if your earnings are less than that for a particular month.
As long as you pay all of your taxes and tributes and have all of your paperwork in order, you are legal. There are many, many dive instructors working absolutely legally here even though their real earnings are less than what they pay taxes on and even though their companies employ fewer than the minimum number of Thais, simply because they pay all of the taxes and tributes they would owe if they did earn the minimum and if they did employ all of those workers.