sounds like alot of work, but it can be done if you use pc monitors.
cabinet 1 needs set up like a standard 2 player cabinet. make sure the video card has dual vga outputs and windows is set to mirror the images (same image on both monitors)
cabinet 2 needs to be set up a little different.
use a usb encoder, change the controls to match up with the standard mame controls for players 3 and 4, then configure mame to use the player 3 controls for player 1, and the player 4 controls for player 2. this way everything will function just like it is a standard 2 player cabinet, just the buttons are mapped to different keys. connect the monitor to a two port kvm switch. one input on the kvm goes to the second PC, the other input connects to the second output from the first cabinet. this can stay connected at all times if necessary.
the only thing you would have to do is unplug the encoder's usb cable from the second cabinet and plug it into the first one, since the buttons are mapped to the standard mame player 3 and 4 keys, it should work fine, then you just press the kvm button to switch the second monitor to display the same thing as the first cabinet.
if you dont want to swap usb cables, you could probably use something like this
http://catalog.belkin.com/IWCatProductPage.process?Product_Id=134172it seems like a litle work, but shouldnt be too bad...the biggest issue is that you will have a video cable and a usb cable running between the two cabinets....other than that, it should be fine.
if I am not explaining this good enough, let me know and i'll try to do better.
(edit)
here is a simple diagram:
http://img351.imageshack.us/img351/2881/dualcabinetsjc3.jpg