If an IM is driven by a VVVF drive and the poles of the motor do not match with the drive configs.. eg., IM is 4 poles but the drive setting is 2 poles.. or the other way around.. then can it create a hazard condition leading to accident or will it be only less efficient motor control?
The number of poles doesn't directly affect anything about how to drive the motor. Regardless of the number of poles, the drive is just outputting three sinusoids offset by 120 degrees, and measures the back-EMF produced as this happens to determine the speed of the motor. All of this works in "electrical rotations", which are implicitly divided by the number of poles so the actual pole count doesn't affect it.
However, many of the other constants in the motor are scaled by the number of poles, which can lead to problems. If you're not entering any other values related to the motor (for example, just output frequency), then the wrong number of poles will be fine. However, if you are using other characteristics of the motor (like resistance, inductance, or slip angle) to determine any configuration of the drive, then you need to consider whether they are scaled by the number of poles.
It will definitely affect any kind of display showing the RPM too, or limit based on shaft RPM, of course. I suspect that's the main (possibly only) place the pole count is used by the drive, but it depends on the details of the drive's configuration.