This scenario is unlikely. If both are Master, then who will initiate the connection and who will accept? Depending on your application, both roles can scan and advertise, but only the master can initiate connection.
However, a device can be a Master in one piconet and a Slave in another which is a different story from yours. Check out the below...
In Bluetooth world the communication is always between a master and a slave. And it is not possible to have 2 connections between 2 devices. So you will have to live with that. Meanwhile I wonder if this is what you need. Regardless of the link role both devices can be GATT client and GATT server. So if you have exactly the same databases on 2 devices they will both be able to use exactly the same code to read, write, send notifications, or whatever you want.
I figured out that all I need to do is make both devices scan and advertise at the same time. In the "connection up" callback function, I stop all advertising and scanning. Each device will be assigned a role (master or slave) by the stack and I use that role to figure out if I want to send write requests or indications. So now two peer devices can share the same functionality and talk to each other over a BLE link.
Whomever becomes slave first will not allow another connection from a master, as victorz says. There could be a race condition there where they both wind up as slaves and neither is master or vice versa, but I haven't seen it.
A connection between 2 masters or 2 slaves is not theoretically possible. On the other hand both sides can be GATT server and GATT client. So you can send write requests from both sides and notifications from both sides. This assumes that GATT databases on both devices allow that.