त्याज्यतुष्टतिननद न्यायः

It takes its origin from the advisability of leaving the banks of a river which is constantly encroaching upon the banks. It is used to denote that it is unvise to put with one that is dangerous in nature.